package com.zzg.dao.impl;

import java.util.List;

import com.zzg.bean.Nanny;
import com.zzg.dao.NannyDAO;
import com.zzg.util.JDBCUtil;
import org.springframework.stereotype.Repository;

@Repository
public class NannyDAOImpl implements NannyDAO {

	@Override
	public void addNanny(Nanny nanny) {
		JDBCUtil.update("insert into tb_nanny (name, age, gender, tel, salary, "
				+ "months, edu, place, address, picture, work_days, phraise, appointments,"
				+ " pid, nanny_type_id, nation, marrital, zodiac, current_city, target_city, status,id_picture) "
				+ "values (?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
				,nanny.getName(),nanny.getAge(),nanny.getGender(),nanny.getTel(),nanny.getSalary(),
				nanny.getMonths(),nanny.getEdu(),nanny.getPlace(),nanny.getAddress(),nanny.getPicture(),
				nanny.getWork_days(),nanny.getPhraise(),nanny.getAppointments(),nanny.getPid(),
				nanny.getNanny_type_id(),nanny.getNation(),nanny.getMarrital(),nanny.getZodiac(),
				nanny.getCurrent_city(),nanny.getTarget_city(),nanny.getStatus(),nanny.getId_picture());
	}

	@Override
	public void delNanny(int id) {
		JDBCUtil.update("delete form tb_nanny where nanny_id = ?", id);
	}

	@Override
	public void updNanny(Nanny nanny) {
		JDBCUtil.update("update tb_nanny set name=?, age=?, gender=?, tel=?, salary=?, "
				+ "months=?, edu=?, place=?, address=?, picture=?, work_days=?, phraise=?, appointments=?,"
				+ " pid=?, nanny_type_id=?, nation=?, marrital=?, zodiac=?, current_city=?, target_city=?, status=?,id_picture) "
				+ "where nanny_id =?"
				,nanny.getName(),nanny.getAge(),nanny.getGender(),nanny.getTel(),nanny.getSalary(),
				nanny.getMonths(),nanny.getEdu(),nanny.getPlace(),nanny.getAddress(),nanny.getPicture(),
				nanny.getWork_days(),nanny.getPhraise(),nanny.getAppointments(),nanny.getPid(),
				nanny.getNanny_type_id(),nanny.getNation(),nanny.getMarrital(),nanny.getZodiac(),
				nanny.getCurrent_city(),nanny.getTarget_city(),nanny.getStatus(),nanny.getId_picture(),nanny.getNanny_id());
	}

	@Override
	public Nanny findNannyById(int id) {
		return JDBCUtil.queryOne(Nanny.class,
				"select * from tb_nanny where nanny_id = ?", id);
	}

	@Override
	public List<Nanny> findAllNanny() {
		return JDBCUtil.queryList(Nanny.class,
				"select * from tb_nanny");
	}

	@Override
	public List<Nanny> findNannyLikeName(String name) {
		return JDBCUtil.queryList(Nanny.class,
				"select * from tb_nanny where name like ?","%"+name+"%");
	}

	@Override
	public List<Nanny> selectNannysLimit(int start, int length) {
		return JDBCUtil.queryList(Nanny.class,
				"select * from tb_nanny limit ?,?", start,length);
	}

	@Override
	public int selectCount() {
		return JDBCUtil.queryCount("select * from tb_nanny");
	}

}
